package com.steel.yfmall.cloud.assistant.impl;

import com.steel.yfmall.cloud.assistant.api.stock.ZgPushProductAPI;
import com.steel.yfmall.cloud.assistant.bean.param.zg.APIZgGoodsTemplateBean;
import com.steel.yfmall.cloud.assistant.dto.zg.result.ZgGoodsTemplateBean;
import com.steel.yfmall.cloud.assistant.view.GoodsTemplateService;
import com.steel.yfmall.cloud.components.utils.base.APIMsgBean;
import com.steel.yfmall.cloud.components.utils.utils.MobileBaseBeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.list.AbstractListDecorator;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: ZgPushProductAPIImpl
 * @author: liuzhijun
 * @date: 2021-03-19 11:24
 **/
@Service
@Slf4j
public class ZgPushProductAPIImpl implements ZgPushProductAPI {

    @Override
    public APIMsgBean<Integer> pushProductInfo(List<APIZgGoodsTemplateBean> apiZgGoodsTemplateBeanList) {
        APIMsgBean<Integer> integerAPIMsgBean = new APIMsgBean<>();
        if (apiZgGoodsTemplateBeanList != null && !CollectionUtils.isEmpty(apiZgGoodsTemplateBeanList)) {
            List<ZgGoodsTemplateBean> zgGoodsTemplateBeanList = new ArrayList<>();
            for (APIZgGoodsTemplateBean apiZgGoodsTemplateBean : apiZgGoodsTemplateBeanList) {
                ZgGoodsTemplateBean zgGoodsTemplateBean = new ZgGoodsTemplateBean();
                MobileBaseBeanUtils.copyAllFields(apiZgGoodsTemplateBean, zgGoodsTemplateBean);
                zgGoodsTemplateBeanList.add(zgGoodsTemplateBean);
            }
            integerAPIMsgBean = goodsTemplateService.checkDataBaseAndBatch(zgGoodsTemplateBeanList);
        }
        return integerAPIMsgBean;
    }

    @Resource
    private GoodsTemplateService goodsTemplateService;
}
